{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#reading dataset\n",
    "import pandas as pd\n",
    "\n",
    "#group multiple files\n",
    "import glob\n",
    "\n",
    "#play with csv files\n",
    "import csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "file_names = sorted(glob.glob('data/*.csv'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "for file_name in file_names:\n",
    "    r = csv.reader(open(file_name))\n",
    "    lines = list(r)\n",
    "    folder = file_name[5:-4]\n",
    "    \n",
    "    for i in range (1, len(lines)):  \n",
    "        if lines[i][1][0] != '0':\n",
    "            lines[i][1] = '0' + lines[i][1]\n",
    "        codes = lines[i][1].split(';')\n",
    "        if folder not in codes:\n",
    "            codes.append(folder)\n",
    "            lines[i][1] = ';'.join(codes)\n",
    "            \n",
    "    writer = csv.writer(open(file_name, 'w'))\n",
    "    writer.writerows(lines)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  },
  "widgets": {
   "state": {},
   "version": "1.1.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
